#region imported Namespaces
using System;
using System.Data;

using BO = PHSRAG.Insight21.BusinessObjects;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.Personnel
{
	#region Class PersonnelSummary
	/// <summary>
	/// The PersonnelSummary class is the facade over the details for a single personnel summary.
	/// </summary>
	public class PersonnelSummary : BO.BusinessObject
	{
		#region Constants
		private const string PersonnelSummaryKey		= "PersonnelSummary_F53BFF25-5B95-41CF-A2DA-7BE39E90430A";
		//Constants to hold the column names
		private const string EmployeeNumberColumnName	= "EmployeeId";
		private const string JobMapIdColumnName			= "EmployeeJobMapId";
		private const string RecordNumberColumnName		= "RecordNumber";
		private const string StatusColumnName			= "Status";
		private const string DivisionColumnName			= "Division";
		//private const string FirstNameColumnName		= "FirstName";
		//private const string LastNameColumnName			= "LastName";
        private const string NameColumn = "Name";
		private const string PayFrequencyTypeColumnName	= "PayFrequencyType";
		private const string JobCodeColumnName			= "JobCode";
		private const string AnnualRateColumnName		= "AnnualRate";
		private const string EffectiveDateColumnName	= "EffectiveDate";
		private const string ErrorFlagColumnName		= "ErrorFlag";
		#endregion

		#region Instance variables
		private DataRow summaryRow;
		#endregion

		#region Public Properties
		/// <summary>
		/// Get the EmployeeNumber. Returns an empty string if the employee has no employee number associated.
		/// </summary>
		public string EmployeeNumber
		{
			get
			{
				object employeeNumber = summaryRow[EmployeeNumberColumnName];
				return (employeeNumber == DBNull.Value) ? string.Empty : employeeNumber.ToString();
			}
		}
		/// <summary>
		/// Get the job map id associated with the employee.
		/// It is a non nullable field.
		/// </summary>
		public int EmployeeJobMapId
		{
			get
			{
				return (int)summaryRow[JobMapIdColumnName];
			}
		}
		/// <summary>
		/// Get the RecordNumber assocaited with the employee
		/// It is a non nullable field.
		/// </summary>
		public int RecordNumber
		{
			get
			{
				return (int)summaryRow[RecordNumberColumnName];
			}
		}
		/// <summary>
		/// Get the employee's status. Return an empty string if the employee has no Status assocaited with him.
		/// </summary>
		public string Status
		{
			get
			{
				object status = summaryRow[StatusColumnName];
				return (status == DBNull.Value) ? string.Empty : status.ToString();
			}
		}
		/// <summary>
		/// Get the division the employee is associcated to. Return an empty string if the employee has no division assocaited with him.
		/// </summary>
		public string Division
		{
			get
			{
				object division = summaryRow[DivisionColumnName];
				return (division == DBNull.Value) ? string.Empty : division.ToString();
			}
		}
		/// <summary>
		/// Get the employee's last name
		/// It is a non nullable field.
		/// </summary>
        //public string LastName
        //{
        //    get
        //    {
        //        return (string)summaryRow[LastNameColumnName];
        //    }
        //}
		/// <summary>
		/// Get the employee's first name
		/// It is a non nullable field.
		/// </summary>
        //public string FirstName
        //{
        //    get
        //    {
        //        return (string)summaryRow[FirstNameColumnName];
        //    }
        //}

        /// <summary>
        /// Get the employee's last name + ", " + first name
        /// It is a non nullable field.
        /// </summary>
        public string Name
        {
            get
            {
                return (string)summaryRow[NameColumn];
            }
        }


        //
		/// <summary>
		/// Get the employee's pay type. Return as empty string if the employee has no pay type assocaited.
		/// </summary>
		public string PayFrequencyType
		{
			get
			{
				object payFrequencyType = summaryRow[PayFrequencyTypeColumnName];
				return (payFrequencyType == DBNull.Value) ? string.Empty : payFrequencyType.ToString();
			}
		}
		/// <summary>
		/// Get the job code associated with the employee. Return an empty string if no job code associated.
		/// </summary>
		public string JobCode
		{
			get
			{
				object jobCode = summaryRow[JobCodeColumnName];
				return (jobCode == DBNull.Value) ? string.Empty : jobCode.ToString();
			}
		}
		/// <summary>
		/// Get the annual rate assigned to the employee. Return 0 is there is no annual rate assigned.
		/// </summary>
		public decimal AnnualRate
		{
			get
			{
				object o = summaryRow[AnnualRateColumnName];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}
		/// <summary>
		/// Get the salary effective date of the employee. Return an empty string is no effective date is assigned to the employee's salary.
		/// </summary>
		public string EffectiveDate
		{
			get
			{
				object effectiveDate = summaryRow[EffectiveDateColumnName];
				return (effectiveDate == DBNull.Value) ? "" : ((DateTime)effectiveDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the salary allocation error flag.
		/// The flag is set on the fly in the SPROC.
		/// </summary>
		public bool ErrorFlag
		{
			get
			{
				return (bool)summaryRow[ErrorFlagColumnName];
			}
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy and assign the DataRow to the instance variable
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="dataRow">DataRow containing personnel summary data</param>
		public PersonnelSummary(ICachePolicy cachePolicy,DataRow dataRow) : base (cachePolicy)
		{
			summaryRow = dataRow;
		}		
		#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache the PersonnelSummary instance using the prevalent cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(PersonnelSummaryKey,this);
		}
		/// <summary>
		/// Remove the PersonnelSummary instance from the cache using the prevalent cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(PersonnelSummaryKey);
		}
		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		public override void Load(string connectionString, params object[] args)
		{			
			throw new Exception("PersonnelSummary cannot be directly loaded.");
		}
		#endregion
	}
	#endregion
}